package designPattern.PipelinePattern2;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import lombok.Getter;
import lombok.Setter;

/**
 * @author jiangwz
 * @create 2019/10/30.
 */
public class StrHandlerContext implements HandlerContext {

    private ExecutorService executor = Executors.newCachedThreadPool();//线程池
    @Setter
    @Getter
    private Handler handler;

    @Setter
    @Getter
    private StrHandlerContext pre = null;
    @Setter
    @Getter
    private StrHandlerContext next;

    public StrHandlerContext(Handler handler) {
        this.handler = handler;
    }

    @Override
    public void fireChannelRead(Object msg) {
        System.out.println(msg);
        if (next == null) {
            return;
        }else {
//            executor.execute(()-> handler.channelRead(next, msg));
            handler.channelRead(next, msg);
        }
    }

    public void doWork(Object msg) {
        System.out.println(msg);
        if (msg instanceof String) {
            fireChannelRead(msg);
        }
    }
}
